package cn.regexp.elasticjob.config;

import com.dangdang.ddframe.job.reg.base.CoordinatorRegistryCenter;
import com.dangdang.ddframe.job.reg.zookeeper.ZookeeperConfiguration;
import com.dangdang.ddframe.job.reg.zookeeper.ZookeeperRegistryCenter;
import org.springframework.beans.factory.annotation.Value;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;

@Configuration
public class RegistryCenterConfig {

    @Bean(initMethod = "init")
    public CoordinatorRegistryCenter createRegistryCenter(@Value("${elastic-job.addr}") String addr,
                                                          @Value("${elastic-job.namespace}") String namespace) {
        // zookeeper 配置
        ZookeeperConfiguration configuration = new ZookeeperConfiguration(addr, namespace);
        // 设置 zookeeper 超时时间
        configuration.setSessionTimeoutMilliseconds(100);
        // 创建注册中心
        return new ZookeeperRegistryCenter(configuration);
    }
}
